<template>
  <div id="app">
    <transition :name="transitionName">
    <router-view></router-view>
    </transition>
  </div>
</template>
<script>
import fastclick from "fastclick";
export default {
  // 监听路由的路径，可以通过不同的路径去选择不同的切换效果
  data() {
    return {
      transitionName: "slide-left",
    };
  },
  // 监听路由的路径，可以通过不同的路径去选择不同的切换效果
  watch: {
    $route(to, from) {
      // from从哪里来  to到哪里去
      if (to.meta.index > from.meta.index) {
        //外--->内 
        this.transitionName = "slide-left";
      } else if (to.meta.index < from.meta.index) {
        //内--->外 
        this.transitionName = "slide-right";
      } else {
        this.transitionName = ""; //同级 无过渡效果
      }
      // 路由跳转后后重置购物车全选按钮
      this.$store.state.allChecked = false
    },
  },
  mounted(){
    fastclick.attach(document.body); //解决移动端点击300ms延时
    // 判断为登录状态后不会刷新vuex里面的用户信息
    if(this.$store.getters.getIsLogin){
      // 刷新后再次获取用户信息
      this.$store.dispatch('getUserIfon')
      // 刷新后再次获取购物车信息
      this.$store.dispatch('getCartList')
      // 刷新后重置购物车全选按钮
      this.$store.state.allChecked = false
    }
  }
};
</script>

<style lang="scss">
* {
  margin: 0;
  padding: 0;
  text-decoration: none;
}
</style>
<style scoped>
#app {
  max-width: 750px;
  margin: 0 auto;
  width: 100%;
}
/*切换样式出错处理*/
/* .router-view {
      width: 100%;
      height: 100%;
      position: absolute;
      top: 0;
      bottom: 0;
      margin: 0 auto;
      -webkit-overflow-scrolling: touch;
  } */

/*切换动画*/
.slide-right-enter-active,
.slide-right-leave-active,
.slide-left-enter-active,
.slide-left-leave-active {
  height: 100%;
  will-change: transform;
  transition: all 500ms;
  position: absolute;
  backface-visibility: hidden;
}

.slide-right-enter {
  opacity: 0;
  transform: translate3d(-100%, 0, 0);
}

.slide-right-leave-active {
  opacity: 0;
  transform: translate3d(100%, 0, 0);
}

.slide-left-enter {
  opacity: 0;
  transform: translate3d(100%, 0, 0);
}

.slide-left-leave-active {
  opacity: 0;
  transform: translate3d(-100%, 0, 0);
}
</style>
